﻿/*********************************************************
 * 开发人员：小兵
 * 创建时间：2012-10-22 11:26:54
 * 描述说明：
 * 
 * 更改历史：
 * 
 * *******************************************************/
namespace Mozlite.Components.Modules
{
    using System;
    using System.Web;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// 页面方法类。
    /// </summary>
    public static class Pages
    {
        /// <summary>
        /// 保存页面内容。
        /// </summary>
        /// <param name="page">页面实例对象。</param>
        /// <returns>返回保存结果。</returns>
        public static bool Save(this Page page)
        {
            bool saved = false;
            if(page.PageID > 0)
                saved = Database.ExecuteNonQuery("UPDATE moz_Pages SET [Title] = @Title, Summary = @Summary, [Body] = @Body, [Key] = @Key, ImageUrl = @ImageUrl, CategoryID = @CategoryID, DefaultUrlFormat = @DefaultUrlFormat WHERE PageID = @PageID AND CultureName = @CultureName;", new
                {
                    Title = page.Title,
                    Summary = page.Summary,
                    Body = page.Body,
                    Key = page.Key,
                    CultureName = page.CultureName,
                    PageID = page.PageID,
                    ImageUrl = page.ImageUrl,
                    CategoryID = page.CategoryID,
                    DefaultUrlFormat = page.DefaultUrlFormat
                });
            else
                saved = Database.ExecuteNonQuery("INSERT INTO moz_Pages([Title], Summary, Body, [Key], CultureName, ImageUrl, CategoryID, Views, DefaultUrlFormat)VALUES(@Title, @Summary, @Body, @Key, @CultureName, @ImageUrl, @CategoryID, 0, @DefaultUrlFormat);", new
                {
                    Title = page.Title,
                    Summary = page.Summary,
                    Body = page.Body,
                    Key = page.Key,
                    CultureName = page.CultureName,
                    PageID = page.PageID,
                    ImageUrl = page.ImageUrl,
                    CategoryID = page.CategoryID,
                    DefaultUrlFormat = page.DefaultUrlFormat
                });
            return saved;
        }
        /// <summary>
        /// 删除页面。
        /// </summary>
        /// <param name="pageIDs">页面ID集合，多个以“,”分割。</param>
        /// <param name="cultureName">区域文化。</param>
        /// <returns>返回删除结果。</returns>
        public static bool Delete(string pageIDs, string cultureName) {
            return Database.ExecuteNonQuery("DELETE FROM moz_Pages WHERE PageID{0} AND CultureName = @CultureName".FormatWith(pageIDs.FormatIDs()), new { CultureName = cultureName });
        }
        
    }
}
